package com.southwind.controller;


import com.southwind.entity.TbAssertOrg;


import com.southwind.entity.TbAssetRole;
import com.southwind.form.SearchForm;
import com.southwind.service.TbAssertOrgService;
import com.southwind.util.ResultVOUtil;
import com.southwind.vo.PageVO;
import com.southwind.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fjh
 * @since 2024-01-09
 */
@RestController
@RequestMapping("/tbAssertOrg")
public class TbAssertOrgController {
    @Autowired
    private TbAssertOrgService tbAssetorgService;
    @PostMapping("/save")
    public ResultVO save(@RequestBody TbAssertOrg tbAssertOrg) {
        boolean save = this.tbAssetorgService.save(tbAssertOrg);
        if (!save) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }

    @GetMapping("/list/{page}/{size}")
    public ResultVO list(@PathVariable("page") Integer page,@PathVariable("size") Integer size){
        PageVO pageVO = this.tbAssetorgService.list(page, size);
        return ResultVOUtil.success(pageVO);
    }
    @GetMapping("/search")
    public ResultVO search(SearchForm searchForm){
        PageVO pageVO = this.tbAssetorgService.search(searchForm);
        return ResultVOUtil.success(pageVO);
    }
    @GetMapping("/findById/{id}")
    public ResultVO findById(@PathVariable("id") Integer id){
        TbAssertOrg tbAssetOrg = this.tbAssetorgService.getById(id);
        return ResultVOUtil.success(tbAssetOrg);
    }

    @PutMapping("/update")
    public ResultVO update(@RequestBody TbAssertOrg tbAssetOrg){
        boolean update = this.tbAssetorgService.updateById(tbAssetOrg);
        if(!update) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }

    @DeleteMapping("/deleteById/{id}")
    public ResultVO deleteById(@PathVariable("id") Integer id){
        boolean remove = this.tbAssetorgService.removeById(id);
        if(!remove) return ResultVOUtil.fail();
        return ResultVOUtil.success(null);
    }

    @GetMapping("/list")
    public ResultVO list(){
        List<TbAssertOrg> OrgList = this.tbAssetorgService.list();
        return ResultVOUtil.success(OrgList);
    }
}

